﻿CREATE PROCEDURE [dbo].[yaf_smiley_save](
                @SmileyID INT  = NULL,
                @BoardID  INT,
                @Code     NVARCHAR(10),
                @Icon     NVARCHAR(50),
                @Emoticon NVARCHAR(50),
                @Replace  SMALLINT  = 0)
AS
    BEGIN
        IF @SmileyID IS NOT NULL
        BEGIN
            UPDATE yaf_Smiley
            SET    Code = @Code,
                   Icon = @Icon,
                   Emoticon = @Emoticon
            WHERE  SmileyID = @SmileyID
        END
        ELSE
        BEGIN
            IF @Replace > 0
            DELETE FROM yaf_Smiley
            WHERE       Code = @Code
            IF NOT EXISTS (SELECT 1
                           FROM   yaf_Smiley
                           WHERE  BoardID = @BoardID
                           AND Code = @Code)
            INSERT INTO yaf_Smiley
                       (BoardID,
                        Code,
                        Icon,
                        Emoticon)
            VALUES     (@BoardID,
                        @Code,
                        @Icon,
                        @Emoticon)
        END
    END


